<?php
namespace app\action\admin;
use core\BaseAction;
use core\App;
use core\JsonInfo;
use core\ParamFilter;
use stdclass;
class RoleAction extends BaseAction{
	//角色列表
	function getList($params,$req,$res){
		return $this->view("admin.role_list");
	}
	//角色列表数据
	function postList($params){
		//初始化查询过滤器
		$filter = new ParamFilter($params);
		//调用业务逻辑
		$service = App::bean('\\app\\service\\admin\\RoleService');
		$service->queryByFilter($filter);
		$this->json($filter->grid);
	}
	
	//用户授权列表
	function getRoleUserList($params,$req,$res){
		return $this->view("admin.role_user_list");
	}
	//角色列表数据
	function postRoleUserList($params){
		//初始化查询过滤器
		$filter = new ParamFilter($params);
		//调用业务逻辑
		$service = App::bean('\\app\\service\\admin\\RoleService');
		$service->queryAuthUserByFilter($filter);
		$this->json($filter->grid);
	}
	//删除授权角色
	function postDelRoleUser($params){
		$info = new JsonInfo();
		if(empty($params['Q_id_in'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\RoleService');
			$filter = new ParamFilter($params);
			$info = $service->delRoleUserByFilter($filter);
		}
		return $this->json($info);
	}
	
	
	function getAll($params){
		$service = App::bean('\\app\\service\\admin\\RoleService');
		$list = $service->table()->get();
		$this->json($list);
	}
	
	//加载新增用户面板
	//function getAdd(){
	//	return $this->view("admin.role_add");
	//}
	//保存修改用户
	function postAdd($params){
		$info = new JsonInfo();
		if(empty($params['name'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\RoleService');
			$service->saveRole($params,$info);
		}
		return $this->json($info);
	}
	
	
	function postDelete($params){
		$info = new JsonInfo();
		if(empty($params['Q_id_in'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\RoleService');
			$service->deleteById($params['Q_id_in'],$info);
		}
		return $this->json($info);
	}
	
	
	function getUserRoles($params){
		if(empty($params['user_id'])){
			$this->json(array());
		}else{
			$userId = $params['user_id'];
			$service = App::bean('\\app\\service\\admin\\RoleService');
			$list = $service->getRolesByUserId($userId);
			$this->json($list);
		}
	}
	
	function postModifyUserRole($params){
		$info = new JsonInfo();
		if(empty($params['userIds'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\RoleService');
			$service->updateUserRole($params['userIds'],$params['roleIds'],$info);
		}
		return $this->json($info);
	}
}